package com.juyu.miliao.api.dao.redis;

import com.juyu.miliao.common.constant.activity.StatisticsSummerActivityRedisKey;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Repository;

import java.time.LocalDate;
import java.util.concurrent.TimeUnit;

/**
 * 统计夏季活动数据
 * @author xuanqicheng
 */
@Repository
public class StatisticsSummerActivityRedisDao {

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    /**
     * 夏季活动寻豆支出
     * @param beans
     * @return
     */
    public long summerActivityExpenditureBeans(long beans){
        String key = StatisticsSummerActivityRedisKey.getStatisticsSummerExpenditureBeansKey(LocalDate.now());
        long num = stringRedisTemplate.opsForValue().increment(key,beans);
        stringRedisTemplate.expire(key,7, TimeUnit.DAYS);
        return num;
    }

    /**
     * 夏季活动寻币支出
     * @param coin
     */
    public long summerActivityExpenditureCoin(long coin){
        String key = StatisticsSummerActivityRedisKey.getStatisticsSummerExpenditureCoinKey(LocalDate.now());
        long num = stringRedisTemplate.opsForValue().increment(key,coin);
        stringRedisTemplate.expire(key,7, TimeUnit.DAYS);
        return num;
    }

    /**
     * 夏季活动领取奖励人数
     */
    public void summerActivityGetRewardsNumbers(long userId){
        String key = StatisticsSummerActivityRedisKey.getStatisticsSummerGetRewardsNumbersKey(LocalDate.now());
        stringRedisTemplate.opsForHyperLogLog().add(key,userId+"");
        stringRedisTemplate.expire(key,7,TimeUnit.DAYS);
    }

    /**
     * 夏日活动参与人数
     * @param userId
     */
    public void summerActivityNumbersOfParticipantsKey(long userId){
        String key = StatisticsSummerActivityRedisKey.getStatisticSummerNumbersOfParticipantsKey(LocalDate.now());
        stringRedisTemplate.opsForHyperLogLog().add(key,userId+"");
        stringRedisTemplate.expire(key,7,TimeUnit.DAYS);
    }

    /**
     * 夏日活动动态广告位点击次数
     * @param userId
     */
    public void summerActivityDynamicOnclickNumbers(long userId){
        String key = StatisticsSummerActivityRedisKey.getStatisticSummerDynamicOnclickNumbersKey(LocalDate.now());
        stringRedisTemplate.opsForHyperLogLog().add(key,userId+"");
        stringRedisTemplate.expire(key,7, TimeUnit.DAYS);
    }

    /**
     * 夏日活动寻寻广告位点击次数
     * @param userId
     */
    public void summerActivityXunXunOnclickNumbers(long userId){
       String key = StatisticsSummerActivityRedisKey.getStatisticSummerXunxunOnclickNumbersKey(LocalDate.now());
       stringRedisTemplate.opsForHyperLogLog().add(key,userId+"");
       stringRedisTemplate.expire(key,7,TimeUnit.DAYS);
    }


}
